<?php
class av2dv
{
    const table  = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF';
    const s      = [11, 10, 3, 8, 4, 6];
    const x      = 177451812;
    const a      = 8728348608;
    const prefix = ['B', 'V'];

    public static function encode($av)
    {
        $av = ($av ^ self::x) + self::a;

        $r = array_merge(self::prefix, ['1', ' ', ' ', '4', ' ', '1', ' ', '7', ' ', ' ']);

        for ($i = 0; $i < 6; $i++) {
            $r[self::s[$i]] = self::table[bcmod(floor($av / pow(58, $i)), 58)];
        }

        return implode('', $r);
    }

    public static function decode(string $bv)
    {
        $table = [];

        for ($i = 0; $i < 58; $i++) {
            $table[self::table[$i]] = $i;
        }

        $r = 0;
        for ($i = 0; $i < 6; $i++) {
            $r += $table[$bv[self::s[$i]]] * pow(58, $i);
        }

        return ($r - self::a) ^ self::x;
    }
}
echo av2dv::encode(1) . PHP_EOL;
echo av2dv::decode('BV1xx411c7mQ');